package com.fuxian.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.fuxian.dao.LessonItemDao;
import com.fuxian.model.Lessonitem;
import com.fuxian.model.Teacherlessons;
import com.fuxian.service.LessonService;
import com.fuxian.service.TeacherLessonService;

@Repository
public class LessonServiceImpl implements LessonService {

	@Resource
	private LessonItemDao lessonItemDao;

	@Resource
	private TeacherLessonService teacherLessonService;

	public void addLessonItem(Lessonitem lessonitem) {
		lessonItemDao.addLessonItem(lessonitem);
	}

	public void deleteLessonItemById(int id) {
		lessonItemDao.deleteLessonItemById(id);
	}

	public void modifyLessonItem(Lessonitem lessonitem) {
		lessonItemDao.modifyLessonItem(lessonitem);
	}

	public List<Lessonitem> selectAlllLessonItem(int start, int size) {

		return lessonItemDao.selectAlllLessonItem(start, size);
	}

	public List<Lessonitem> selectLessonItemByClassifId(int classifId) {

		return lessonItemDao.selectLessonItemByClassifId(classifId);
	}

	public Lessonitem selectLessonItemByLessonId(int lessonId) {
		return lessonItemDao.selectLessonItemByLessonId(lessonId);
	}

	public List<Lessonitem> selectLessonItemByTeacherId(int teacherId) {
		// get lesson id by teacher id
		List<Teacherlessons> teacherlessonList = teacherLessonService
				.selectTeacherLessonsByTeacherId(teacherId);

		// get lesson item by lesson id

		List<Lessonitem> lessonList = new ArrayList<Lessonitem>();
		for (Teacherlessons teacherlessons : teacherlessonList) {
			lessonList.add(lessonItemDao
					.selectLessonItemByLessonId(teacherlessons.getLesson_id()));
		}
		return lessonList;
	}

	public int selectCount(int classifId) {
		return lessonItemDao.selectCount(classifId);
	}

}
